package net.qunzhi.modules.cms.controller;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Arrays;

import io.github.swagger2markup.GroupBy;
import io.github.swagger2markup.Language;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import net.qunzhi.common.utils.BaseQuery;
import net.qunzhi.common.annotation.SysLog;
import net.qunzhi.modules.cms.query.SqlServerDateQuery;
import net.qunzhi.modules.cms.query.StateDateQuery;
import net.qunzhi.modules.cms.service.DzFlowDataService;
import net.qunzhi.modules.cms.service.XjFlowDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import net.qunzhi.modules.cms.entity.TbFlowStateEntity;
import net.qunzhi.modules.cms.service.TbFlowStateService;
import net.qunzhi.common.utils.PageUtils;
import net.qunzhi.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;


/**
 * 调度中心流量数据
 *
 * @author zjr
 * @date 2021-09-10 15:48:00
 */
@Api(tags = "调度中心流量数据相关")
@RestController
@RequestMapping("cms/tbFlowState")
public class TbFlowStateController {
    @Autowired
    private TbFlowStateService tbFlowStateService;
    @Autowired
    private DzFlowDataService dzFlowDataService;
    @Autowired
    private XjFlowDataService xjFlowDataService;

    /**
     * 列表
     */
    @ApiOperation("列表")
    @GetMapping("/list")
    @RequiresPermissions("cms:tbFlowState:list")
    public R list(StateDateQuery query){
        PageUtils page = tbFlowStateService.queryPage(query);

        return R.ok().put("page", page);
    }

    @ApiOperation("丹灶列表")
    @GetMapping("/dzList")
    @RequiresPermissions("cms:tbFlowState:list")
    public R dzList(SqlServerDateQuery query){
        PageUtils page = dzFlowDataService.queryPage(query);

        return R.ok().put("page", page);
    }

    @ApiOperation("西江列表")
    @GetMapping("/xjList")
    @RequiresPermissions("cms:tbFlowState:list")
    public R xjList(SqlServerDateQuery query){
        PageUtils page = xjFlowDataService.queryPage(query);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("cms:tbFlowState:info")
    public R info(@PathVariable("id") Integer id){
		TbFlowStateEntity tbFlowState = tbFlowStateService.getById(id);

        return R.ok().put("tbFlowState", tbFlowState);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @SysLog("调度中心流量数据修改")
    @PostMapping("/update")
    @RequiresPermissions("cms:tbFlowState:update")
    public R update(@RequestBody TbFlowStateEntity tbFlowState){
		tbFlowStateService.updateById(tbFlowState);

        return R.ok();
    }

//    @ApiOperation("fffff")
//    @GetMapping("/fffff")
    public void attendListffff(BaseQuery query, HttpServletRequest request) throws MalformedURLException {
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.MARKDOWN)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                .build();

        Swagger2MarkupConverter.from(new URL("http://localhost:8081/waternetwork/v2/api-docs"))//确保这个地址能访问
                .withConfig(config)
                .build()
                .toFile(Paths.get("./docs/markdown/generated/all"));
    }

}
